<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="support.*, java.util.*, java.sql.*"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<link rel="stylesheet" type="text/css" href="../resource/columnCSS.css" /> 
	<link rel="stylesheet" type="text/css" href="../resource/styleCSS.css" /> 	
	<title>Provide degrees - Choose discipline</title>
</head>
<body>
	<%
		// Get Vector of countries
		// UPDATE: make it so that we extract from database rather than from support
 		/*support s = new support(); 		
	 	String path = config.getServletContext().getRealPath("majors.txt");
		Vector majors = s.getMajors(path); */
		Vector majors = new Vector();
		try {
			//Registering Postgresql JDBC driver
			Class.forName("org.postgresql.Driver");
		} catch (ClassNotFoundException e) {
			System.err.println("ClassNotFoundException: " + e);
		} 
		try {	
			//Open a connection to the database
			Connection conn = DriverManager.getConnection(
					"jdbc:postgresql://localhost:5432/CSE135_SP11?"
					+ "user=postgres&password=postgres");
	
			PreparedStatement pstmt = conn.prepareStatement(
					"SELECT discipline FROM Disciplines;");
			
			ResultSet rset = pstmt.executeQuery();
			
			while(rset.next())
				majors.add(rset.getString("discipline"));
			
			rset.close();
			pstmt.close();
			conn.close();
		
			} catch (SQLException e) {
				throw new RuntimeException(e);
			}

		
		String university = (String) request.getParameter("university");
		
		// Get session information
		String fname = (String)session.getAttribute("fname");
		String lname = (String)session.getAttribute("lname");
		String mname = (String)session.getAttribute("mname");
		
		String citizen = (String)session.getAttribute("citizen");
		String residence = (String)session.getAttribute("residence");
		
		String address = (String)session.getAttribute("address"); 
		String city = (String)session.getAttribute("city");
		String state = (String)session.getAttribute("state");
		Integer zipcode = (Integer)session.getAttribute("zipcode");
		Integer areacode = (Integer)session.getAttribute("areacode");
		Integer number = (Integer)session.getAttribute("number");
		Integer countrycode = (Integer)session.getAttribute("countrycode");
		Boolean domestic = (Boolean)session.getAttribute("domestic");	
		
		Vector degreeInfo = (Vector) session.getAttribute("degreeInfo");
		
		if (university != null && degreeInfo != null && degreeInfo.size() < 2) {
			degreeInfo.add(university);
			session.setAttribute("degreeInfo", degreeInfo);
		}
		else {
			System.err.println("[DEBUG] Unable to add university " +
					"to degree Info");
		}
	%>
	<p class="sansserif">
	<div class="container">
	<div class="center_div">
		<div class="colmask threecol">
		<div class="colmid">
		<div class="colleft">
			<div class="bodycol">
				<p>Applicant: <i><%= fname%> <%= mname%> <%= lname%></i></p> 
				<p>Citizenship: <i><%= citizen%></i></p>
				<p>Country of Residence: <i><%= residence%></i></p> 
				<p>Address: <i><%= address%></i></p>
				<p>City: <i><%= city%></i> 
				<%
					if ( state != null ) {
						out.println("State: <i>" + state + "</i>");
					}
				%>
				Zip Code: <i><%= zipcode%></i></p>
				<p>Telephone: <i><%= areacode %> <%= number%></i>
				<%
					if ( countrycode != null ) {
						out.println("Country Code: <i>" + countrycode + "</i>");
					}
				%>
				</p>
				<p>Domestic: <i><%= domestic%> </i> </p>
				<br>
			</div>
			<div class="sidecol">
				<p><a href="../invalidate.jsp">Logout</a></p>
			</div>
		</div>
		</div>
		</div>
		<div style="clear:both;"></div>
		
		<p><b>Provide Degree - Select Discipline</b> </p>
				
		<form method="GET" action="moreDegreesJSP.jsp">
			<%
				String major;
				int index;
					
				for (index = 0; index< majors.size(); index += 1) {
					major = (String)majors.get(index);
			
					out.print("<input type=\"radio\" name=\"major\" value=\"" + major + "\" />"); 
					out.print(major + "<br>");
				}
			%>
			<ul class="none">
				<li>Other: <input type="text" name="major" /></li>
			<li>Time of Graduation</li>
			<ul class="none">
				<li>Month: <input type="text" size="2" name="month" />
					Year: <input type="text" size="3" name="year" /></li>
			</ul>
			<li>GPA or Expected GPA:<input type="text" size="2" name="gpa" /></li>
			<li>Title of Degree:
			
			<select name="title">
				<option value="BS">BS</option>
				<option value="MS">MS</option>
				<option value="PhD">PHD</option>
			</select></li>
				
			<li>Transcript: <input type="file" name="transcript" accept="pdf"/></li>
	
			</ul>
			<input type="submit" value="Submit"/>
		</form>
	<div style="clear:both;"></div>
	</div>
	</div>		
</body>
</html>